package com.ylsf.blog.controller;

import com.ylsf.blog.service.SendCommentService;
import com.ylsf.blog.service.impl.SendCommentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 发送评论控制类
 */
@WebServlet("/sendComment")
public class SendCommentServlet extends HttpServlet {
    private SendCommentService sendCommentService=new SendCommentServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String author = request.getParameter("author");
        String commentText = request.getParameter("commentText");
        String dateTime = request.getParameter("dateTime");
        String articleId = request.getParameter("articleId");
        Integer integer = sendCommentService.sendComment(author, commentText, new Date(dateTime), Integer.valueOf(articleId));
        if(integer.equals(1)) {
            response.getWriter().print("评论成功");
        }else{
            response.getWriter().print("评论失败");
        }
    }
}
